package types

import (
	"cuelang.org/go/cue/ast"
	"fmt"
	"strings"
)

type Reference struct {
	vv *ast.SelectorExpr
}

func (t *Reference) Value(ref bool) string {
	mType := t.vv.X.(*ast.Ident).Name
	sType := t.vv.Sel.(*ast.Ident).Name
	if strings.HasPrefix(sType, "#") {
		format := "%s.%s"
		if ref {
			format = "*%s.%s"
		}
		return fmt.Sprintf(format, mType, strings.TrimPrefix(sType, "#"))
	}
	return fmt.Sprintf("%s.%s", mType, sType)
}

func (t *Reference) Default() string {
	return ""
}
